/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.batavia.testiing;

import com.batavia.domain.AmbilFlight;
import com.batavia.domain.BantuLihatFlight;
import com.batavia.domain.BookingDone;
import com.batavia.domain.Flight;
import com.batavia.impl.ImplementAmbilFlight;
import com.batavia.impl.ImplementBookingDone;
import com.batavia.impl.ImplementFlight;
import com.batavia.impl.ImplementLogin;
import com.batavia.inter.AirlineInterface;
import com.batavia.inter.AmbilFlightInterface;
import com.batavia.inter.BookingInterface;
import com.batavia.inter.LoginInterface;
import com.gargoylesoftware.htmlunit.util.Cookie;
import java.util.List;
import org.joda.time.DateTime;
import org.junit.Test;

/**
 *
 * @author Saiful Bahri
 * blog    : http://bahrie27.wordpress.com/
 * twitter : @bahrie127
 */
public class LoginTesting {

    @Test
    public void test() {
        LoginInterface login = new ImplementLogin();

        AirlineInterface service = new ImplementFlight();

        AmbilFlightInterface afService = new ImplementAmbilFlight();

        BookingInterface bookingService = new ImplementBookingDone();

        DateTime berangkat = new DateTime(2011, 6, 15, 0, 0, 0, 0);

        DateTime expire = new DateTime().plusDays(30);

        // Cookie cookie = new Cookie("web.batavia-air.com", "PHPSESSID", "3e1c875860c93f83036a9cea1ba4a074", "/", expire.toDate(), false);
        Cookie cookie = new Cookie("null", "null");

        boolean status = login.cekLogin(cookie);

        if (status) {


            List<Flight> result = service.search(cookie, berangkat.toDate(), "JOG", "CGK", 1, 0);


//        Assert.assertFalse(result.isEmpty());

            for (Flight f : result) {
                System.out.println("============= Lihat Flight ============");
                System.out.println("batavia-air");
                System.out.println("No flight : " + f.getFltNo());
                System.out.println("Dari : " + f.getOrigin());
                System.out.println("Ke : " + f.getDestination());
                System.out.println("berangkat : " + f.getDep());
                System.out.println("tiba : " + f.getArr());
                System.out.println("Via : " + f.getVia());
                System.out.println("=======================================");
            }

//            HtmlPage page = service.getPage();
//            Cookie cookie2=service.getCookie();
            BantuLihatFlight blf = result.get(0).getBfl();
            List<AmbilFlight> resultAmbilFlight = afService.search(cookie, 5, blf);

            for (AmbilFlight af : resultAmbilFlight) {
                System.out.println("=============Ambil flight==============");
                System.out.println("No Penerbangan : " + af.getNoPenerbangan());
                System.out.println("Perjalanan : " + af.getPerjalanan());
                System.out.println("Tanggal : " + af.getTanggal());
                System.out.println("Hari : " + af.getHari());
                System.out.println("rute : " + af.getRute());
                System.out.println("Keterangan : " + af.getKeterangan());
                System.out.println("Harga Dewasa : " + af.getDetailhargaDewasa());
                System.out.println("Detail Pajak : " + af.getDetailPajak());
                System.out.println("Klass : " + af.getDetailKelas());
                System.out.println("=======================================");
            }

        } else {

            System.out.println("login salah");
            System.out.println("Proses dengan Login Baru....");

            cookie = login.login("terminalkenan", "2584");

            if (cookie == null) {
                System.out.println("login gagal karena pasword ma username salah");
            } else {

                List<Flight> result = service.search(cookie, berangkat.toDate(), "JOG", "CGK", 1, 0);


//        Assert.assertFalse(result.isEmpty());

                for (Flight f : result) {
                    System.out.println("========= Lihat Flight ===========");
                    System.out.println("batavia-air");
                    System.out.println("No flight : " + f.getFltNo());
                    System.out.println("Dari : " + f.getOrigin());
                    System.out.println("Ke : " + f.getDestination());
                    System.out.println("berangkat : " + f.getDep());
                    System.out.println("tiba : " + f.getArr());
                    System.out.println("Via : " + f.getVia());
                    System.out.println("=================================");
                }


                BantuLihatFlight blf = result.get(0).getBfl();
                List<AmbilFlight> resultAmbilFlight = afService.search(cookie, 5, blf);

                for (AmbilFlight af : resultAmbilFlight) {
                    System.out.println("==========ambil flight=============");
                    System.out.println("No Penerbangan : " + af.getNoPenerbangan());
                    System.out.println("Perjalanan : " + af.getPerjalanan());
                    System.out.println("Tanggal : " + af.getTanggal());
                    System.out.println("Hari : " + af.getHari());
                    System.out.println("rute : " + af.getRute());
                    System.out.println("Keterangan : " + af.getKeterangan());
                    System.out.println("Harga Dewasa : " + af.getDetailhargaDewasa());
                    System.out.println("Detail Pajak : " + af.getDetailPajak());
                    System.out.println("Klass : " + af.getDetailKelas());
                    System.out.println("===================================");
                }

                BantuLihatFlight blf2 = resultAmbilFlight.get(0).getBlf();
                List<BookingDone> resultBooking = bookingService.search(cookie, blf, "Mr.", "Saiful", "Bahri", "9113444156234", "bah", "084548791123");
                for (BookingDone bkDone : resultBooking) {
                    System.out.println("=============booking finish===============");
                    System.out.println("PNR  : " + bkDone.getPnr());
                    System.out.println("Limit Time : " + bkDone.getLimitTime());
                    System.out.println("Agent : " + bkDone.getAgent());
                    System.out.println("");
                    System.out.println("Penumpang : "+bkDone.getPenumpang());
                    System.out.println("");
                    System.out.println("From/To : " + bkDone.getFromTo());
                    System.out.println("No Flight : " + bkDone.getNoFlight());
                    System.out.println("Class : " + bkDone.getKlass());
                    System.out.println("Date : " + bkDone.getDate());
                    System.out.println("route Datang : " + bkDone.getRouteDari());
                    System.out.println("Route tujuan : " + bkDone.getRouteTujuan());
                    System.out.println("Pax Type : " + bkDone.getPaxType());
                    System.out.println("Harga Dasar : " + bkDone.getHargaDasar());
                    System.out.println("pajak : " + bkDone.getPajak());
                    System.out.println("jumlah Pax : " + bkDone.getJmlPax());
                    System.out.println("Total harga : " + bkDone.getTotalHarga());
                    System.out.println("Pax Paid : " + bkDone.getPaxPaid());
                    System.out.println("==========================================");

                }




            }
        }

    }
}
